package top.oylan.example.app.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import top.oylan.example.app.BaseActivity;
import top.oylan.example.app.R;
import top.oylan.example.app.adapter.MainAdapter;
import top.oylan.example.app.fragment.MainFragment;

public class MainActivity extends BaseActivity {

    @BindView(R.id.main_view_pager)
    ViewPager viewPager;
//    @BindView(R.id.main_tab_home)
//    Button tabHome;
//    @BindView(R.id.main_tab_book)
//    Button tabBook;
//    @BindView(R.id.main_tab_find)
//    Button tabFind;
//    @BindView(R.id.main_tab_me)
//    Button tabMe;

    ArrayList<MainFragment> viewList;

    MainAdapter mainAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        viewList = new ArrayList<MainFragment>();
        viewList.add(new MainFragment("首页"));
        viewList.add(new MainFragment("发现"));
        viewList.add(new MainFragment("通讯录"));
        viewList.add(new MainFragment("我"));
        mainAdapter = new MainAdapter(getSupportFragmentManager(), viewList);
        viewPager.setAdapter(mainAdapter);

//        setTabClickListener(tabHome,0);
//        setTabClickListener(tabFind,1);
//        setTabClickListener(tabBook,2);
//        setTabClickListener(tabMe,3);
    }

    private void setTabClickListener(Button btn, final int index) {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager.setCurrentItem(index,false);
            }
        });
    }
}
